package com.liuche.rpc.consumer;

import com.liuche.rpc.common.model.User;
import com.liuche.rpc.common.service.UserService;
import com.liuche.rpc.proxy.ServiceProxyFactory;

/**
 * @author：liuche
 * @Date：2024年03月07日 15:42
 * @Description：
 */
public class ConsumerExample {
    public static void main(String[] args) throws InterruptedException {
        // 动态代理
        UserService userService = ServiceProxyFactory.getProxy(UserService.class);
        User user = new User();
        user.setName("我是程序员刘彻");
        // 调用
        User newUser = userService.getUser(user);
        if (newUser != null) {
            System.out.println(newUser.getName());
        } else {
            System.out.println("user == null");
        }

        // 第二次调用看有没有走缓存
        user.setName("我是刘祖彻👋");
        User secUser = userService.getUser(user);
        if (secUser != null) {
            System.out.println(secUser.getName());
        } else {
            System.out.println("user == null");
        }

//        Thread.sleep(20000);

        // 第三次调用看有没有走缓存
        user.setName("我是刘祖彻👋，hello！");
        User thirdUser = userService.getUser(user);
        if (thirdUser != null) {
            System.out.println(thirdUser.getName());
        } else {
            System.out.println("user == null");
        }
    }
}
